package com.YCH.consummer.Listener;

import com.YCH.common.rabbitMQ.RabbitmqConfig;
import com.YCH.consummer.service.MailService;
import com.YCH.model.user.vo.MailVo;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: 辉哥
 * @DateTime: 2020/11/9 下午5:32
 * @Description: TODO
 */
@Component
@Log4j2
public class ReceiveMailHandler {
    @Autowired
    MailService mailService;

    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void accept_email(byte[] msg, Message message) {
        try {
            MailVo mailVo = JSONObject.parseObject(msg, MailVo.class);
            // System.out.println(mailVo);
            mailService.sendMail(mailVo);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }
    }

}
